package cn.wmelon.shell.command;

import cn.wmelon.shell.command.builder.CommandBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

/**
 * @author watermelon
 * @time 2020/4/12
 */
public abstract class AbstractCommand implements Command {
    public Logger logger = LoggerFactory.getLogger(AbstractCommand.class);

    /**
     * 命令builder
     */
    protected CommandBuilder builder;

    public AbstractCommand() {
        this.builder = new CommandBuilder();
    }

    public AbstractCommand(CommandBuilder builder) {
        this.builder = builder;
    }

    @Override
    public String getCommandString() {
        long start = System.currentTimeMillis();
        logger.debug("开始执行命令,当前时间:{}", LocalDateTime.now());
        String command = commandContent();
        long end = System.currentTimeMillis();
        logger.debug("结束执行命令,当前时间:{}", LocalDateTime.now());
        logger.debug("执行命令耗时:{}毫秒", end - start);
        return command;
    }

    abstract String commandContent();
}
